//  PicLayout.m
//  HYHoney
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "PicLayout.h"
#import "ModelOfPic.h"
#import "UIImageView+WebCache.h"
#import "DKNightVersion.h"

@interface PicLayout ()

@property (nonatomic, retain)UIActivityIndicatorView *activity;


@end



@implementation PicLayout

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self createVC];
    }
    return self;
}


- (void)dealloc{

    [_descN release];
    [_imageN release];
    [super dealloc];
}


- (void)createVC{

    self.imageN = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageN];
    
    self.descN = [[UILabel alloc] init];
    self.descN.numberOfLines = 0;
    self.descN.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.descN];
}


- (void)layoutSubviews{

    [super layoutSubviews];
    
    self.imageN.frame = CGRectMake(40, 20, self.frame.size.width - 80, 200);
    self.imageN.layer.cornerRadius = 10;
    self.imageN.layer.masksToBounds = YES;

    self.descN.frame = CGRectMake(20, 20 + 15 + 200, self.frame.size.width - 40, [[self class] heightForLabel:self.descN.text]);    // 自适应
}


+ (CGFloat)heightForLabel:(NSString *)text{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 40, 0) options: NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil];
    
    return rect.size.height;
}


+ (CGFloat)heightForCell:(ModelOfPic *)model{
    
    CGFloat height =  [PicLayout heightForLabel:model.like_desc];

    return height + 20 + 15 + 200;
}


- (void)passmodel:(ModelOfPic *)modelN{

    [self.imageN sd_setImageWithURL:[NSURL URLWithString:modelN.path] placeholderImage:[UIImage imageNamed:@"jzz"]];
    self.descN.text = modelN.like_desc;
    self.descN.dk_textColorPicker = DKColorWithRGB(0x000000, 0xc6e2ef);
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
